;(function ($) {
	$.extend($.jqFormatter,{
		
		/**---------------------------------------------------------------------------trimBegin**/
		//trimBegin初始化
		trimBegin : function(formatRules){
			function handle(e){
				var $target = $($.EventUtils.getTargetByEvent(e));
				if(formatRules.trimBegin && formatRules.trimBegin === true){
					$.jqFormatUtils.trimBegin($target);
				}
			}
			var $this = this,elm = this[0]; 
			if($.browser.msie){
				$this.bind('keyup',handle);
			}else{
				elm.addEventListener('keyup',handle,true);
			}
		},
		/**---------------------------------------------------------------------------end trimBegin**/
		
		
		/**---------------------------------------------------------------------------trimEnd**/
		//trimEnd初始化
		trimEnd : function(formatRules){
			function handle(e){
				var $target = $($.EventUtils.getTargetByEvent(e));
				if(formatRules.trimEnd && formatRules.trimEnd === true){
					$.jqFormatUtils.trimEnd($target);
				}
			}
			var $this = this,elm = this[0]; 
			if($.browser.msie){
				$this.bind('keyup',handle);
			}else{
				elm.addEventListener('keyup',handle,true);
			}
		},
		/**---------------------------------------------------------------------------end trimEnd**/
		

		/**---------------------------------------------------------------------------trimBoth**/
		//trimBoth初始化
		trimBoth : function(formatRules){
			function handle(e){
				var $target = $($.EventUtils.getTargetByEvent(e));
				if(formatRules.trimBoth && formatRules.trimBoth === true){
					$.jqFormatUtils.trimBoth($target);
				}
			}
			var $this = this,elm = this[0]; 
			if($.browser.msie){
				$this.bind('keyup',handle);
			}else{
				elm.addEventListener('keyup',handle,true);
			}
		},
		/**---------------------------------------------------------------------------end trimBoth**/
		
		/**---------------------------------------------------------------------------trimAll**/
		//trimAll初始化
		trimAll : function(formatRules){
			function handle(e){
				var $target = $($.EventUtils.getTargetByEvent(e));
				if(formatRules.trimAll && formatRules.trimAll === true){
					$.jqFormatUtils.trimAll($target);
				}
			}
			var $this = this,elm = this[0]; 
			if($.browser.msie){
				$this.bind('keyup',handle);
			}else{
				elm.addEventListener('keyup',handle,true);
			}
		},
		/**---------------------------------------------------------------------------end trimAll**/
		
		/**---------------------------------------------------------------------------toUpperCase**/
		//toUpperCase初始化
		toUpperCase : function(formatRules){
			function handle(e){
				var $target = $($.EventUtils.getTargetByEvent(e));
				if(!$.jqValidatorUtils.isEmpty($target.val())&&formatRules.toUpperCase && formatRules.toUpperCase === true){
					$.jqFormatUtils.toUpperCase($target);
				}
			}
			var $this = this,elm = this[0]; 
			elm.style.textTransform = 'uppercase';
			if($.browser.msie){
				$this.bind('keyup',handle);
			}else{
				elm.addEventListener('keyup',handle,true);
			}	
		},
		/**---------------------------------------------------------------------------end toUpperCase**/
		
		/**---------------------------------------------------------------------------toLowerCase**/
		//toLowerCase初始化
		toLowerCase : function(formatRules){
			function handle(e){
				var $target = $($.EventUtils.getTargetByEvent(e));
				if(!$.jqValidatorUtils.isEmpty($target.val())&&formatRules.toLowerCase && formatRules.toLowerCase === true){
					$.jqFormatUtils.toLowerCase($target);
				}
			}
			var $this = this,elm = this[0]; 
			elm.style.textTransform = 'lowercase';
			if($.browser.msie){
				$this.bind('keyup',handle);
			}else{
				elm.addEventListener('keyup',handle,true);
			}
		},
		/**---------------------------------------------------------------------------end toLowerCase**/
		
		/**---------------------------------------------------------------------------currency**/
		//currency初始化
		currency : function(formatRules){
			function handle(e){
				var $target = $($.EventUtils.getTargetByEvent(e));
				if(!$.jqValidatorUtils.isEmpty($target.val())&&formatRules.currency && formatRules.currency === true){
					$.jqFormatUtils.formatCurrency($target);
				}
			}
			var $this = this,elm = this[0]; 
			if($.browser.msie){
				$this.bind('blur',handle);
			}else{
				elm.addEventListener('blur',handle,true);
			}
		},
		/**---------------------------------------------------------------------------end currency**/
		
		/**---------------------------------------------------------------------------checkedValueMap**/
		//checked 当复选框用作单选作用时,勾选复选框是value应为true/1/yes或其它,反选复选框时以为false/0/no.
		//<k:checkbox formatRules="{checkedValueMap:{checked:true,unChecked:false}}"/>,
		//<k:checkbox formatRules="{checkedValueMap:{checked:1,unChecked:0}}"/>,
		//<k:checkbox formatRules="{checkedValueMap:{checked:yes,unChecked:no}}"/>,
		checkedValueMap : function(formatRules){
			var $this = this,elm = this[0];
			if($('#'+$this.attr("id")+':checked').attr("checked")){
				$this.val(formatRules.checkedValueMap.checked)
			}else{
				$this.val(formatRules.checkedValueMap.unChecked)
			}
			
			function handle(e){
				var $target = $($.EventUtils.getTargetByEvent(e));
				if($('#'+$target.attr("id")+':checked').attr("checked")){
					$target.val(formatRules.checkedValueMap.checked)
				}else{
					$target.val(formatRules.checkedValueMap.unChecked)
				}
			}
			if($.browser.msie){
				elm.attachEvent('onclick',handle);
			}else{
				elm.addEventListener('click',handle,true);
			}
			
		},
		/**---------------------------------------------------------------------------end checkedValueMap**/
		
		/**---------------------------------------------------------------------------toHalfAngle**/
		//customExpression 自定义正则表达式格式化
		customExpression : function(formatRules){
			function handle(e){
				var $target = $($.EventUtils.getTargetByEvent(e));
				if(!$.jqValidatorUtils.isEmpty($target.val()) && !$.StringUtils.isEmpty(formatRules.customExpression)){
					var regExp = new RegExp(formatRules.customExpression);
					if(!regExp.test($target.val())){
						//将输入框的值全部匹配正则表达式,如果不匹配删除,最后输入的字符
						alert(1);
					} 
				}
			}
			var $this = this,elm = this[0];
			if($.browser.msie){
				$this.bind('keyup',handle);
			}else{
				elm.addEventListener('keyup',handle,true);
			}
		},
		/**---------------------------------------------------------------------------end checkedValueMap**/
		
		/**---------------------------------------------------------------------------toHalfAngle**/
		//number 数值数据格式化
		number : function(formatRules){
			function handle(e){
				var $target = $($.EventUtils.getTargetByEvent(e)),_val = $target.val();
				//判断配置是否为空并且是否是复杂配置
				if($.isPlainObject(formatRules.number) && !$.isEmptyObject(formatRules.number)){
					//如果不为空并且为复杂配置，用自定义的配置覆盖默认配置
					formatRules.number = $.extend({positive:false,intPart:1,decPart:0},formatRules.number);
				}
				//判断是否是单纯配置true
				if(formatRules.number === true){
					return $.jqFormatUtils.number(e,$.EventUtils.getTargetByEvent(e),true,18,0);
				}
				else if($.isPlainObject(formatRules.number) && !$.isEmptyObject(formatRules.number)){
					//验证输入值是否符合配置要求，不符合不显示
					return $.jqFormatUtils.number(e,$.EventUtils.getTargetByEvent(e),formatRules.number.positive,formatRules.number.intPart,formatRules.number.decPart);
				}
				return false;
			}
			
			var $this = this,elm = this[0];
			$this.css({
				"ime-mode": "Disabled"
			});
			if($.browser.msie){
				$this.bind('keypress',handle);
			}else{
				elm.addEventListener('keypress',handle,true);
			}
		}
		/**---------------------------------------------------------------------------end checkedValueMap**/
	});
})(jQuery);